using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using Boggle.Net.Model;

namespace Boggle.Net.ViewModels
{
    public class StatisticsViewModel
    {
        public StatisticsViewModel(ICollection<AcceptablePlay> wordList, TimeSpan searchTime)
        {
            Contract.Requires<ArgumentNullException>(wordList != null);
            Contract.Requires<ArgumentException>(searchTime >= TimeSpan.Zero);

            var distinctList = wordList.GroupBy(result => result.Word).ToList();

            SearchTime = searchTime;
            TotalWords = wordList.Count;
            TotalDistinctWords = distinctList.Count;
            MaximumScore = distinctList.Sum(candidates => candidates.Max(play => play.Score));
        }

        public TimeSpan SearchTime { get; private set; }

        public int MaximumScore { get; private set; }

        public int TotalWords { get; private set; }

        public int TotalDistinctWords { get; private set; }
    }
}